"""
RedFlag-TC000036   闪光灯功能检查
检查倒计时应用场景
"""
__author__ = "ldm"

import sys
import os
# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *
auto_setup(__file__)

shooter = CameraVideoShooter()

log("------------------------------闪光灯启动/关闭场景-----------------------------")
"""
进入相机拍摄
将相机切换为后置摄像头
通过图片定义闪光灯状态
通过判断切换前闪光灯状态和切换后的闪光灯状态进行断言
"""
shooter.enter_photograph()
shooter.ensure_back_camera()

try:
    if exists(Template(r"tpl1746023373275.png", record_pos=(0.411, -0.797), resolution=(1224, 2700))):
        log("闪光灯关闭")
    else:
        shooter.click_element(shooting_page_flashlight_elenment)
        shooter.assert_image_exists(r"tpl1746023393445.png", "断言失败，闪光灯切换失败",(0.411, -0.797), (1224, 2700))
        log("闪光灯由关闭变为开启")

    if exists(Template(r"tpl1746023393445.png", record_pos=(0.406, -0.799), resolution=(1224, 2700))):
        log("闪光灯开启")
    else:
        shooter.click_element(shooting_page_flashlight_elenment)
        shooter.assert_image_exists(r"tpl1746023373275.png", "断言失败，闪光灯切换失败",record_pos=(0.411, -0.797), resolution=(1224, 2700))
        log("闪光灯由开启变为关闭")
except Exception as e:
    log(f"出现异常: {e}")

# 关闭应用
stop_app(UGC_package_name)

